<template>
	<view class="container">
		<view v-for="(item, index) in dataList" :key='index'
		 style="display: flex;flex-direction: column;background-color: #FFF;padding: 16rpx;border-bottom: 1rpx solid #eee;">
			<view style="margin-left: 20rpx;font-size: 32rpx;font-weight: bold;limitLineNumOfOne">{{item.name}}</view>
			<view style="margin-left: 20rpx;font-size: 28rpx;">核销码ID：{{item.code}}</view>
			<view style="margin-left: 20rpx;font-size: 28rpx;limitLineNumOfOne">内容：{{item.content}}</view>
			<view style="margin-left: 20rpx;font-size: 28rpx;">状态：{{item.statusLabel}}</view>
			<view style="margin-left: 20rpx;font-size: 28rpx;">用户手机号：{{item.userModel.phone}} (ID:{{item.userModel.code}})</view>
			<view style="margin-left: 20rpx;font-size: 28rpx;">核销方式：{{item.cancelTypeLabel}}</view>
			<view style="margin-left: 20rpx;font-size: 28rpx;">核销时间：{{$time.dateFormat('yyyy-mm-dd HH:MM:SS', item.cancelTime)}}</view>
		</view>
		<view style="padding-top: 300rpx;" v-if='showEmpty'>
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view>
	</view>
</template>

<script>
	import { coupon } from '@/api/coupon.js'
	export default{
		components: {},
		data() {
			return {
				page: 1,
				size: 20,
				dataList: [],
				showEmpty: false,
				isLastPage: false,
				lesseeId: ''
			}
		},
		onLoad() {
			if(this.$Route.query.lesseeId){
				this.lesseeId = this.$Route.query.lesseeId
			}
			this.getDatList()
		},
		onPullDownRefresh() {
			this.page = 1
			this.getDatList()
		},
		onReachBottom() {
			if(this.isLastPage) {
				return
			}
			this.getDatList()
		},
		methods:{
			getDatList() {
				var params = {
					page: this.page,
					size: this.size,
					status: 'has_use',
					user: this.$storage.getStorageDataSync(this.$store.state.userInfo).id,
					lessee: this.lesseeId
				}
				coupon.getCouponList(params).then(res => {
					uni.stopPullDownRefresh();
					if (res.data.code == 10000) {
						if(this.page == 1){
							this.dataList = []
						}
						var list = res.data.data.list
						this.dataList = [...this.dataList, ...list]
						this.showEmpty = this.dataList.length<1
						if (res.data.data.next) {
							this.page += 1
						} else {
							this.isLastPage = true
						}
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	
</style>
